package cn.xgx.web.controller.backstage;

import cn.xgx.result.ResponseData;
import cn.xgx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/backstage")
public class BackstageIndexController {
    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public ResponseData login(String username, String password){
        //生成token并存储
        return userService.login(username,password);
    }

    @DeleteMapping("/logout")
    public ResponseData logout(HttpServletRequest request){
        //读取token的值
        String token = request.getHeader("access_token");
        //移除token
//        userService.removeToken(token);
        return  userService.removeToken(token);
    }
}
